import pytest
import requests
import logging

class TestA3mallCart():
    #提取变量
    Token = None
    GWCspid = None
    def setup_method(self):
        print("开始测试")
    def teardown_method(self):
        print("结束测试")

    #登录接口
    try:
        def test_login(self):
            url ="http://10.59.9.12:7001/api/public/login"
            head = {"Content-Type": "application/json"}
            data ={"username":"13811033962","password":"123456"}
            res = requests.post(url=url,headers=head,json=data)
            print(res.json())
            TestA3mallCart.Token ="Bearer "+res.json()["data"]["token"]
            logging.info(res.json())
    except Exception as e:
        logging.info(e)

    #首页商品列表接口
    try:
        def test_splb(self):
            url = "http://10.59.9.12:7001/api/point?page=1&type=0&sort=1"
            head = {"Content-Type": "application/json"}
            res = requests.get(url=url, headers=head)
            print(res.json())
            logging.info(res.json())
    except Exception as e:
        logging.info(e)

    #商品详情接口
    try:
        def test_spxq(self):
            url = "http://10.59.9.12:7001/api/goods/view?id=69"
            head = {"Content-Type": "application/json"}
            res = requests.get(url=url, headers=head)
            print(res.json())
            # TestA3mallCart.GWCspid = res.json()["data"][0]["id"]
            logging.info(res.json())
    except Exception as e:
        logging.info(e)

    #添加购物车接口
    try:
        def test_addr(self):
            url = "http://10.59.9.12:7001/api/cart/add"
            head = {"Content-Type": "application/json","Auth-Token":TestA3mallCart.Token}
            data = {"id":69,"sku_id":"","num":1}
            res = requests.post(url=url, headers=head, json=data)
            print(res.json())
    except Exception as e:
        logging.info(e)

    #提交订单接口
    try:
        def test_tjdd(self):
            url = "http://10.59.9.12:7001/api/order/confirm?id=69&type=buy&sku_id=&num=1&shipping_type=1"
            head = {"Content-Type": "application/json", "Auth-Token": TestA3mallCart.Token}
            res = requests.get(url=url, headers=head)
            print(res.json())
    except Exception as e:
        logging.info(e)
    #支付接口
    try:
        def test_zf(self):
            url ="http://10.59.9.12:7001/api/order/create"
            head = {"Content-Type": "application/json", "Auth-Token": TestA3mallCart.Token}
            data ={"id":"69","type":"buy","address_id":801,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=69&sku_id=&num=1&type=buy","sku_id":"","num":"1"}
            res = requests.post(url=url, headers=head,json=data)
            print(res.json())
    except Exception as e:
        logging.info(e)
    #查看订单接口
    def chakandd(self):
        url = "http://10.59.9.12:7001/api/order/detail"
        head = {"Content-Type": "application/json", "Auth-Token": TestA3mallCart.Token}
        data = {"id":"382614"}
        res = requests.post(url=url, headers=head, json=data)
        print(res.json())